Language Model Middleware
Provider middleware. Per invariants I-9 and R-11, provider differences (Anthropic-specific options, OpenAI-specific options, on-device-only sampling knobs) live in middleware — NEVER in agent or orchestration code. If you find yourself branching on model.modelId.startsWith("...") inside an agent, that's a missing middleware.
Other middleware uses: logging, telemetry, retry on transient failure, default-provider-options injection, request/response transformation.
Mirrors v6's LanguageModelV3Middleware shape: each hook receives a MiddlewareCallContext exposing both doGenerate AND doStream so a stream-wrapping middleware can synthesize a stream out of the downstream generate result (which is exactly what ai.torad.aisdk.middleware.simulateStreamingMiddleware needs and couldn't do under the prior (params, next) shape that only exposed the same-direction call).
Functions
Override the model id the wrapper presents (null = keep the wrapped model's).
Override the provider name the wrapper presents (null = keep the wrapped model's).
Override the supported-URL patterns the wrapper presents (null = keep the wrapped model's).
Transform the call params before wrapGenerate/wrapStream run, for the given operation. The transformed params flow into both the wrap hooks and the downstream call. This is the params-only seam — a middleware can implement just this (e.g. ai.torad.aisdk.middleware.defaultSettingsMiddleware). Default: pass through. Mirrors v6's transformParams({ type, params, model }).
Wrap the one-shot generate call. Default: pass through.
Wrap the streaming call. Default: pass through.